﻿#region << 文件说明 >>

/*----------------------------------------------------------------
 * 命名空间：Vampirewal.BlogCore.Controls
 * 唯一标识：2613f40c-42f7-4deb-9aac-7d17b0eea3b9
 * 文件名：Col
 *
 * 创建者：杨程
 * 电子邮箱：235160615@qq.com
 * 创建时间：2024/6/25 9:44:00
 * 版本：V1.0.0
 * 描述：
 *
 * ----------------------------------------------------------------
 * 修改人：
 * 时间：
 * 修改说明：
 *
 * 版本：V1.0.1
 *----------------------------------------------------------------*/

#endregion << 文件说明 >>

namespace Vampirewal.BlogCore;

/// <summary>
/// 列控件
/// </summary>
public sealed class Column : ContainerControlBase
{
    /// <summary>
    /// 构造函数
    /// </summary>
    internal Column()
    {
    }

    public override string Title { get; set; }
    public override List<ControlBase> Children { get; internal set; }
    public override string Id { get; set; }

    /// <summary>
    /// 间隔
    /// </summary>
    internal string Span { get; set; }

    public override string ConverToHtml()
    {
        StringBuilder sb = new StringBuilder();

        Param parms = new Param();

        if (!string.IsNullOrEmpty(Span))
        {
            parms.Add($"span=\"{Span}\"");
        }

        sb.AppendLine($"<el-col {parms}>");

        foreach (var item in Children)
        {
            sb.AppendLine(item.ConverToHtml());
        }
        sb.AppendLine($"</el-col>");

        return sb.ToString();
    }
}

public static partial class App
{
    /// <summary>
    /// 创建列控件
    /// </summary>
    /// <param name="span"></param>
    /// <param name="colAction"></param>
    /// <returns></returns>
    public static Column CreateColumn(Action<List<ControlBase>> colAction, string span = "")
    {
        Column column = new Column()
        {
            Id = GenerateId(),
            Children = new List<ControlBase>(),
            Title = "Column"
        };

        colAction.Invoke(column.Children);

        return column;
    }
}